import Vue from 'vue'
import Router from 'vue-router'
import index from '@/components/index'

import myindex from '@/components/myindex'
import myreg from '@/components/myreg'
import mylogin from '@/components/mylogin'
import myhome from '@/components/myhome'
import dinglogin from '@/components/dinglogin'
import showcate from '@/components/showcate'
import addcourse from '@/components/addcourse'
import courselist from '@/components/courselist'
import coursedetail from '@/components/coursedetail'

Vue.use(Router)

var routes = [
        {
          path:'/index',
          name:'index',
          component:index
        },
        {
          path:'/',
          name:'myindex',
          component:myindex
        },
        {
          path:'/myreg',
          name:'myreg',
          component:myreg
        },
        {
          path:'/mylogin',
          name:'mylogin',
          component:mylogin
        },
        {
          path:'/dinglogin',
          name:'dinglogin',
          component:dinglogin
        },
        {
          path:'/showcate',
          name:'showcate',
          component:showcate
        },
        {
          path:'/addcourse',
          name:'addcourse',
          component:addcourse
        },
        {
          path:'/courselist',
          name:'courselist',
          component:courselist
        },
        {
          path:'/coursedetail',
          name:'coursedetail',
          component:coursedetail
        },
        {
          path:'/myhome',
          name:'myhome',
          component:myhome,
          // 拦截器使用
          beforeEnter:(to,from,next)=>{
              if(localStorage.getItem('username')){
                console.log('登录了')
                next();
              }else{
                next('/mylogin')
              }
          }
        },

        
]

export default new Router({
  routes:routes,
  mode:'history'   /*hash*/
})
